import Vue from 'vue'
import App from './App.vue'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import Vant from 'vant'
import 'vant/lib/index.css';

import router from './router/index.js'

import store from './store/index.js'

Vue.config.productionTip = false

Vue.use(ElementUI);
Vue.use(Vant);


// 全局路由守卫
router.beforeEach((to, from, next) => {
  // console.log('去到', to.path)
  // console.log('从这个', from.path)
  if (sessionStorage.getItem('Shopping-Token')) {
    next()
  } else {
    if (to.path !== '/login') {
      next({path: '/login'})
    } else {
      next()
    }
  }
})

// 第一次
// from ---- /
// login


// 无限循环
// from --- login
// to ---- login

// 第二次
// from --- login
// to --- home

// 第三次
// from --- home
// to --- login


new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')